export type ChatQueryType = {
  messages?: ChatMessageType[]
  accessToken?: string
  stream?: boolean
  model?: string
  [params: string]: any
}
export interface ChatMessageType
  extends ChatMessageBaseType,
    ChatErrorCodeType,
    ChatMessageResponseType,
    ChatgptMsg {}
export interface ChatMessageBaseType {
  role?: string
  content?: string
  createTime?: number | string
  [params: string]: any
}
export interface ChatMessageResponseType {
  id?: string
  object?: string
  sentence_id?: string | number
  is_end?: boolean
  created?: number | string
  result?: string
  is_truncated?: boolean
  need_clear_history?: boolean
  finish_reason?: string
  usage?: any
  model?: string
  system_fingerprint?: string
  choices?: Choices[]
}

interface Choices {
  index?: number
  delta?: ChatMessageBaseType
  logprobs?: any
  finish_reason?: string
}

export interface ChatErrorCodeType {
  error_code?: string | number
  error_msg?: string
}

export interface ChatMessageState {
  contents: ChatMessageType[]
  createTime: string | number
  chat?: ChatMessageBaseType
}

export type ChatMessageAction = {
  setContents: (content: ChatMessageType[]) => void
  getContents: ({
    start,
    end,
    timestamp,
    size
  }: {
    start?: number
    end?: number
    size?: number
    timestamp?: string | number
  }) => ChatMessageType[]
  delContent: () => void
  addContent: (content: ChatMessageType) => void
  setChat: (chat?: ChatMessageBaseType) => void
}
interface ChatgptMsg {
  error?: ChatgptError
}

interface ChatgptError {
  message?: string
  type?: string
  param?: string
  code?: string
}
